<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
%>
<jsp:include page="../../import.jsp" flush="true" />

<body>


<SCRIPT LANGUAGE="JavaScript">
<!--
$(function(){
	$("#editDiv").dialog({
		autoOpen: false,
		bgiframe: true,
		height: 700,
		width:600,
		modal: true,
		buttons: {
			"提交": function() { 
				//$(this).dialog("close"); 
				_submit();
			}, 
			"取消": function() { 
				$(this).dialog("close"); 
			} 
		}
	});
});
//-->


</SCRIPT>
<jsp:include page="roleCache.jsp" flush="true" />

<div id="editDiv" title="权限规则配置"  style="display:none">
	<span align='center' >
		<FORM METHOD='POST' ACTION='<%=path%>/security/urlRuleManage!update.action' onsubmit="return checkData();">
		<TABLE>
		<TR>
			<TD valign='top' >
			<INPUT TYPE="hidden" NAME="id"   id="id" value=''>
			<INPUT TYPE="hidden" NAME="index"   id="index" value=''>
			<INPUT TYPE="hidden" NAME="rid"   id="rid" value=''>
			<INPUT TYPE="hidden" NAME="gid"   id="gid" value=''>
			<TABLE >
			<TR>
					<TD nowrap>规则名称：</TD>
					<TD><INPUT TYPE="text" NAME="name" id="name"  value=''></TD>
			</TR>
			<TR>
					<TD colspan="2">URL匹配：<br>
						<TEXTAREA NAME="urlpattern" id="urlpattern"  ROWS="8" COLS="40"></TEXTAREA>
					</TD>
			</TR>
			</TABLE>
			</TD>
			<TD valign='top'>
			<iframe src='<%=path%>/security/roleInclude.action?forward=list&index=quaryRoles' frameborder=0  width="99%"  height="300px"  id="RolesFrame"></iframe>

			</TD>
		</TR>
		</TABLE>			
		</FORM>
	</span>
</div>

<table class="QueryTable">
<thead>
	<th>规则名称</th>
	<th>URL匹配</th>
	<th>角色</th>
	<th>角色组</th>
	<th>操作[<A HREF="javascript:addNewUrlRule();">新增规则</A>][<A HREF="synchronize.action">同步</A>]</th>
</thead>
<!-- even odd -->
 <s:iterator value="rb.resultList" id="m" status="cust_stat">  
 <TR class='<s:if test="#cust_stat.even">anthor_tr</s:if>'>  
		<TD><s:property value="NAME"/></TD>
		<TD><s:property value="URLPATTERN"/></TD>
		<TD><SCRIPT LANGUAGE="JavaScript">document.write(toTranslate('<s:property value="RID"/>'));	</SCRIPT></TD>
		<TD><s:property value="GID"/></TD>
		<TD>[<A HREF='javascript:editUrlRule(<s:property value="ID"/>,"<s:property value="NAME"/>","<s:property value="URLPATTERN"/>","<s:property value="RID"/>","<s:property value="GID"/>",<s:property value="ISSAFE"/>)'>修改</A>]
		<!-- <s:if test="#m.SENDNUM==null&&#m.WAITNUM==null&&#m.FINISHNUM==null"> -->
			/ [<A HREF='javascript:delUrlRule(<s:property value="ID"/>,"<s:property value="NAME"/>")'>删除</A>]
		<!-- </s:if> -->
		</TD>
	</TR>
 </s:iterator> 
</table>
<jsp:include page="../../pageination.jsp" flush="true" />

<!-- <TEXTAREA id="debug" ROWS="50" COLS="100"></TEXTAREA> -->
</body>
<SCRIPT LANGUAGE="JavaScript">
/*
var _roleFrame = window.frames["RolesFrame"]；
var tran = function(rid){
	if(_roleFrame==null){
		return rid;
	}
	return _roleFrame.toTranslate(rid);
}
*/
var _submit = function(){
	
	if($('#name').val()==''){
		alert("登录名必须输入！");
	}else{
		$('#editDiv').dialog('close');
		wait.show();
		$('#rid').val(window.frames["RolesFrame"].getDtreeValues());
		$('form:first').submit();
	}
}

var editUrlRule = function(id,name,urlPattern,rid,gid,isSafe){	
	$('#editDiv').dialog('open');
	$('#id').val(id);
	$('#name').val(name);
	$('#urlpattern').val(urlPattern);
	//$('#info').val(info);
	window.frames["RolesFrame"].setDtreeValues(rid);
	$('#index').val('editUrlRule');
	
}

var delUrlRule = function(id,name){
	if(confirm('确定删除任务【'+name+'】?')){
		$('#id').val(id);
		$('#name').val('delete');
		$('#index').val('deleteUrlRule');
		_submit();
	}
}
var addNewUrlRule = function(){
	$('input').val('');
	window.frames["RolesFrame"].setDtreeValues(null);
	$('#editDiv').dialog('open');
	$('#index').val("addUrlRule");
}


//$("#debug").val($('.dtree').html());
</SCRIPT>
